import axiosRequest from "@/api/axiosRequest.ts";

const BaseUrl = '/admin/category'

const getCategoryDetail = (id:number) => axiosRequest({
    url:BaseUrl + '/detail' ,
    method: 'GET',
    params: {
        id: id
    }
})

const getCategoryPage = (page:number=1, pageSize?:number) => axiosRequest({
    url: BaseUrl + '/page',
    method: 'GET',
    params: {
        current: page,
        size: pageSize
    }
})

const addCategory = (data:Category) => axiosRequest({
    url: BaseUrl + '/add',
    method: 'POST',
    data : data
})

const updateCategory = (data:Category) => axiosRequest({
    url: BaseUrl + '/update',
    method: 'PUT',
    data : data
})

const deleteCategory = (id:number) => axiosRequest({
    url: BaseUrl + '/delete',
    method: 'DELETE',
    params: {
        id: id
    }
})

export const categoryApi = {
    getCategoryList : () => axiosRequest.get(BaseUrl + '/list'),
    getCategoryTree : () => axiosRequest.get(BaseUrl + '/tree'),
    getCategoryDetail,
    getCategoryPage,
    addCategory,
    updateCategory,
    deleteCategory,
}
